Inheritance:
In object-oriented programming, inheritance is the concept that when a class of objects is defined, any subclass that is defined can inherit the definitions of one or more general classes. This means for the programmer that an object in a subclass need not carry its own definition of data and methods that are generic to the class (or classes) of which it is a part. This not only speeds up program development; it also ensures an inherent validity to the defined subclass object (what works and is consistent about the class will also work for the subclass).
Sometimes base class known as generalized class and derived class known as specialized class.
Example:
Class x
{
Public static int add (int a,int b)
{
Return (a+b);
}
}
Class y:X
{
Public static int mul(inta,intb)
{
Return(a*b);
}
}
Static void main()
{
X obj=new y();
Obj.add(5,6);
}
Anonymous User
28-Feb-2019Nice Blog.
Sushant Mishra
19-Jun-2017It was really helpful to read this post.